<?php
namespace Home\Controller;

/**
 * ConfigController
 * 配置控制器
 */
class ConfigController extends CommonController {

    /**
     * 用户协议
     */
    public function user_agreement(){
        $config_Model = M('system_config');
        $agreement = $config_Model->where(['key'=>"USER_AGREEMENT"])->getField('value');

        $agreement = htmlspecialchars_decode($agreement);
        $this->assign('agreement',$agreement);
        $this->display();
    }

    /**
     * 编辑用户协议
     */
    public function edit_agreement(){
        $config_Model = M('system_config');
        $agreement = I('post.agreement');

        $result = $config_Model->where(['key'=>"USER_AGREEMENT"])->save(['value'=>$agreement]);

        if($result){
            $this->ajaxReturn(['code'=>0,'message'=>'修改协议成功']);
        }else{
            $this->ajaxReturn(['code'=>-1,'message'=>"修改协议失败，稍后请重试"]);
        }
    }

}
